﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using System.Data;
using DLL;
using BLL;

namespace WebApplication2
{
    public partial class WebForm1 : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack) 
            {
                string s = LoginUser.UserID;
            }
        }

        protected void btnIPls_Click(object sender, EventArgs e)
        {

            var ls = new LongCarShareInfo();
            //车主发布信息
            if (txtGoCity.Text != "" && txtDtn.Text != "" && txtPtc.Text != ""&&txtPpl.Text!="")
            {
                
                ls.LGoCity = txtGoCity.Text.Trim();
                ls.Distination = txtDtn.Text.Trim();
                ls.LGoDate = $"{Request.Form["content"].ToString()}{DropDownList1.SelectedValue}";
                ls.LContain = int.Parse(txtPpl.Text.Trim());
                ls.LPPeople = int.Parse(txtPtc.Text.Trim());
                ls.UserID = "13558365701";
                ls.LPType = "车主";
                ls.LStatus = "等待中";
                ls.LPTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                if (rad.Checked)
                {
                    ls.LCarType = rad.Text;
                }
                else if (rad2.Checked)
                {
                    ls.LCarType = rad2.Text;
                }
                else if (rad3.Checked)
                {
                    ls.LCarType = rad3.Text;
                }
                else if (rad4.Checked)
                {
                    ls.LCarType = rad4.Text;
                }
                else if (rad5.Checked)
                {
                    ls.LCarType = rad5.Text;
                }
                else if (rad6.Checked)
                {
                    ls.LCarType = rad6.Text;
                }


                if (rad7.Checked)
                {
                    ls.LCost = rad7.Text;
                    
                }
                else if (rad8.Checked)
                {
                    ls.LCost = rad8.Text;
                    
                }
                else if (rad9.Checked)
                {
                    ls.LCost = aText.Text;
                }
                ls.LCWord = txtCt.Text.Trim();
                //搜索城市是否存在
                if (LongSortBLL.Search(ls).Rows.Count > 0)
                {
                    if (LongSortBLL.Add(ls)>0)
                    {
                        //添加数据
                        btnIPls.Attributes.Add("onclick", "return confirm('发布成功！');");
                    }
                    else
                    {
                        btnIPls.Attributes.Add("onclick", "return confirm('发布失败！');");
                    }
                    
                }
                else
                {
                    btnIPls.Attributes.Add("onclick", "return confirm('城市名错误或不存在！');");
                }

            }
            //乘客发布拼车
            else if(txtGoCity.Text != "" && txtDtn.Text != "" && txtPtc.Text != "" && txtPpl.Text == "")
            {
                ls.LGoCity = txtGoCity.Text.Trim();
                ls.Distination = txtDtn.Text.Trim();
                ls.LGoDate = $"{Request.Form["content"].ToString()}{DropDownList1.SelectedValue}";
                ls.LPPeople = int.Parse(txtPtc.Text.Trim());
                ls.UserID = "13558365701";
                ls.LPType = "乘客";
                ls.LStatus = "等待中";
                ls.LPTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                if (rad7.Checked)
                {
                    ls.LCost = rad7.Text;

                }
                else if (rad8.Checked)
                {
                    ls.LCost = rad8.Text;

                }
                else if (rad9.Checked)
                {
                    ls.LCost = aText.Text;
                }
                ls.LCWord = txtCt.Text.Trim();

                //搜索城市是否存在
                if (LongSortBLL.Search(ls).Rows.Count > 0)
                {

                    if (LongSortBLL.PAdd(ls)>0)
                    {
                        //添加数据
                        btnIPls.Attributes.Add("onclick", "return confirm('发布成功！');");
                    }
                    else
                    {
                        btnIPls.Attributes.Add("onclick", "return confirm('发布失败！');");
                    }
                }
                else
                {
                    btnIPls.Attributes.Add("onclick", "return confirm('城市名错误或不存在！');");
                }
                
            }
            else
            {
                btnIPls.Attributes.Add("onclick", "return confirm('请输入完整信息！');");
                //Response.Write(" <script>function window.onload() {alert( ' 弹出的消息' ); } </script> ");
            }
        }


    }
}